﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using kim.Common;

namespace kim
{
    public partial class ProductList : kim.UI.ManagePage
    {
        protected string StrPage;
        protected int pageSize, pageIndex, typeid;
        protected void Page_Load(object sender, EventArgs e)
        {
            typeid = KIMRequest.GetInt("typeid", 1);

            Label1.Text = "案例中心";
            if (!IsPostBack)
            {
                TreeBind(typeid);

            }
            GetStrPage();

        }
        #region 绑定类别=================================
        private void TreeBind(int _channel_id)
        {
            BLL.CClass bll = new BLL.CClass();
            DataTable dt = bll.GetList(0, _channel_id);

            this.ddlParentId.Items.Clear();
            this.ddlParentId.Items.Add(new ListItem("显示全部分类", "0"));
            foreach (DataRow dr in dt.Rows)
            {
                string Id = dr["id"].ToString();
                int ClassLayer = int.Parse(dr["Depth"].ToString());
                string Title = dr["ClassName"].ToString().Trim();

                if (ClassLayer == 1)
                {
                    this.ddlParentId.Items.Add(new ListItem(Title, Id));
                }
                else
                {
                    Title = "├ " + Title;
                    Title = Utils.StringOfChar(ClassLayer - 1, "　") + Title;
                    this.ddlParentId.Items.Add(new ListItem(Title, Id));
                }
            }
        }
        #endregion
        private void GetStrPage()
        {
            string strwhere = "ChannelID=" + typeid;
            string strUrl = "ProductList.aspx?p=__id__&tyepid=" + typeid;
            if (ddlParentId.SelectedValue != "0")
            {
                strwhere = "ChannelID=" + typeid + "and ClassID=" + ddlParentId.SelectedValue;
                strUrl = "ProductList.aspx?p=__id__&ClassID=" + ddlParentId.SelectedValue + "&tyepid=" + typeid;
            }

            pageSize = 10;
            pageIndex = KIMRequest.GetInt("p", 1);
            kim.BLL.Product bll = new kim.BLL.Product();
            int count = SqlDbHelper.GetPageCurrent("Product", strwhere);
            using (DataSet dt = bll.GetNewsPager(pageIndex, pageSize, "", "Sort Desc", strwhere))
            {
                rptlist.DataSource = dt;
                rptlist.DataBind();
            }
            StrPage = kim.Common.Utils.OutPageList(pageSize, pageIndex, count, strUrl, 8);
        }
        protected void lbtnqx_Click(object sender, CommandEventArgs e)
        {
            LinkButton l = (LinkButton)sender;
            Model.Product moNews = new BLL.Product().GetModel(int.Parse(l.CommandName));
            BLL.Product bllNews = new BLL.Product();
            if (moNews.DesignerID == 1)
            {
                moNews.DesignerID = 0;
                bllNews.Update(moNews);
                typeid = kim.Common.KIMRequest.GetInt("typeid", 1);
                GetStrPage();
            }
            else
            {
                moNews.DesignerID = 1;
                bllNews.Update(moNews);
                typeid = kim.Common.KIMRequest.GetInt("typeid", 1);
                GetStrPage();
            }

        }
    }
}

/**/